package com.huweilong.tingshu.view_object;

import com.huweilong.tingshu.data_object.AlbumDO;
import com.huweilong.tingshu.data_object.TrackDO;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author 是阿秋啊
 * @date 2022/07/22 10:28
 **/
@Data
public class BindVO {
    public UserVO currentUser;
    public Integer aid;
    public String title;
    public List<TrackVO> trackList;

    public BindVO(UserVO currentUser, AlbumDO albumDO, List<TrackDO> trackDOList) {
        this.currentUser = currentUser;
        this.aid = albumDO.aid;
        this.title = albumDO.title;
        // 通俗方法
//        this.trackList = new ArrayList<>();
//        for (TrackDO trackDO : trackDOList) {
//            TrackVO view = new TrackVO(trackDO.tid,trackDO.title);
//            trackList.add(view);
//        }
        // 流式方法
//        Stream<TrackDO> stream = trackDOList.stream();
//        Stream<TrackVO> stream2 = stream.map(new Function<TrackDO, TrackVO>() {
//
//            @Override
//            public TrackVO apply(TrackDO trackDO) {
//                return new TrackVO(trackDO.tid, trackDO.title);
//            }
//        });
//        List<TrackVO> trackVOList = stream2.collect(Collectors.toList());

        // lambda表达式
        this.trackList = trackDOList.stream().map(d -> new TrackVO(d.tid, d.title)).collect(Collectors.toList());
    }
}